package com.nsgf.library.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

import io.vov.vitamio.utils.Log;

import java.text.DecimalFormat;

public class GsonUtils {

    private static Gson mGson = new GsonBuilder()
            .setExclusionStrategies(new ExclusionStrategy() {
                @Override
                public boolean shouldSkipField(FieldAttributes f) {
                    // Skip DecimalFormat fields to avoid conflicts
                    return f.getDeclaredClass() == DecimalFormat.class;
                }

                @Override
                public boolean shouldSkipClass(Class<?> clazz) {
                    // Skip DecimalFormat class entirely
                    return clazz == DecimalFormat.class;
                }
            })
            .create();

    public static <T> T json2Bean(String json, Class<T> clazz) {
        try {
            return mGson.fromJson(json, clazz);
        } catch (Exception e) {
            Log.e("GsonUtils:" + e.toString());
            return null;
        }
    }
}